import time

from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()

driver.get("https://news.sina.com.cn")

# 实现网页垂直滑动
driver.execute_script('window.scrollTo(0, 10000)')

# 等待2秒
time.sleep(2)

# 实现网页垂直滑动
driver.execute_script('window.scrollTo(0,0)')

# 点击科技
driver.find_element_by_xpath('//*[@id="blk_cNav2_01"]/div/a[15]/span').click()

# 创建鼠标对象
action = ActionChains(driver)

# 将鼠标悬停到数码上面
action.move_to_element(driver.find_element_by_xpath('//*[@id="tech_head"]/div[7]/div/a')).perform()

# 点击电脑
action.double_click(driver.find_element_by_xpath('//*[@id="tech_head"]/div[7]/div/ul/li[1]/a')).perform()

# 将窗口最大化
driver.maximize_window()

handles = driver.window_handles

# 等待
time.sleep(2)
# 切换到当前窗口
driver.switch_to.window(handles[1])
driver.close()

time.sleep(2)
# 切换到当前窗口
driver.switch_to.window(handles[0])
driver.close()
